package com.springcloud.sc.ucpv5.client.commondata.data;

import com.springcloud.sc.ucpv5.client.commondata.datachange.DataExChange;
import com.google.protobuf.Message;
import lombok.Data;

/**
 * Generated from IDL struct "UserInfo".
 *
 * @author JacORB IDL compiler V 2.3-beta-2, 14-Oct-2006
 * @version generated at 2014-10-29 11:48:54
 */
@Data
public final class UserInfo extends DataExChange {
    public UserInfo() {
    }

    public String UserTelno = "";
    public String UserName = "";
    public String password = "";
    public int UserType;
    public int Priority;
    public int UserStatus;
    public String GrpList = "";
    public int PttPriority;
    public int GroupPriority;
    public String Workplace = "";
    public String Address = "";
    public String Contact = "";
    public String Desc = "";
    public String addtime = "";
    public int Odb;
    public com.springcloud.sc.ucpv5.client.commondata.data.SSInfoType[] SSInfoTypelist;
    public com.springcloud.sc.ucpv5.client.commondata.data.UserLocal LocalInfo;
    public String AuthNodeIDList = "";
    public String longitude = "";
    public String latitude = "";
    public String zoom = "";
    public String UserIconName = "";
    public int UserShowType;
    public int UserMediaType;
    public String UserMediaID = "";
    public String utRegIp = "";
    public String keep2 = "";
    public String keep3 = "";
    public String keep4 = "";

    public UserInfo(String UserTelno, String UserName, String password, int UserType, int Priority, int UserStatus,
                    String GrpList, int PttPriority, int GroupPriority, String Workplace, String Address, String Contact,
                    String Desc, String addtime, int Odb, com.springcloud.sc.ucpv5.client.commondata.data.SSInfoType[] SSInfoTypelist,
                    com.springcloud.sc.ucpv5.client.commondata.data.UserLocal LocalInfo, String AuthNodeIDList, String longitude, String latitude,
                    String zoom, String UserIconName, int UserShowType, int UserMediaType, String UserMediaID, String utRegIp,
                    String keep2, String keep3, String keep4) {
	this.UserTelno = UserTelno;
	this.UserName = UserName;
	this.password = password;
	this.UserType = UserType;
	this.Priority = Priority;
	this.UserStatus = UserStatus;
	this.GrpList = GrpList;
	this.PttPriority = PttPriority;
	this.GroupPriority = GroupPriority;
	this.Workplace = Workplace;
	this.Address = Address;
	this.Contact = Contact;
	this.Desc = Desc;
	this.addtime = addtime;
	this.Odb = Odb;
	this.SSInfoTypelist = SSInfoTypelist;
	this.LocalInfo = LocalInfo;
	this.AuthNodeIDList = AuthNodeIDList;
	this.longitude = longitude;
	this.latitude = latitude;
	this.zoom = zoom;
	this.UserIconName = UserIconName;
	this.UserShowType = UserShowType;
	this.UserMediaType = UserMediaType;
	this.UserMediaID = UserMediaID;
	this.utRegIp = utRegIp;
	this.keep2 = keep2;
	this.keep3 = keep3;
	this.keep4 = keep4;
    }

    public Message dataChangeCommonToProBufData() {
	try {
	    com.proto.uuos_sdk_pb.UserInfo.Builder builder_dst = com.proto.uuos_sdk_pb.UserInfo.newBuilder();
	    builder_dst.setUserTelno(UserTelno);
	    builder_dst.setUserName(UserName);
	    builder_dst.setPassword(password);
	    builder_dst.setUserType(UserType);
	    builder_dst.setPriority(Priority);
	    builder_dst.setUserStatus(UserStatus);
	    builder_dst.setPttPriority(PttPriority);
	    builder_dst.setGroupPriority(GroupPriority);
	    builder_dst.setWorkplace(Workplace);
	    builder_dst.setAddress(Address);
	    builder_dst.setContact(Contact);
	    builder_dst.setDesc(Desc);
	    builder_dst.setAddtime(addtime);
	    builder_dst.setOdb(Odb);
	    builder_dst.setAuthNodeIDList(AuthNodeIDList);
	    builder_dst.setLongitude(longitude);
	    builder_dst.setLatitude(latitude);
	    builder_dst.setZoom(zoom);
	    builder_dst.setUserIconName(UserIconName);
	    builder_dst.setUserShowType(UserShowType);
	    builder_dst.setUserMediaType(UserMediaType);
	    builder_dst.setUserMediaID(UserMediaID);
	    builder_dst.setUtRegIp(utRegIp);
	    builder_dst.setKeep2(keep2);
	    builder_dst.setKeep3(keep3);
	    builder_dst.setKeep4(keep4);

	    String[] GrpList_ = GrpList.split("#");
	    if (GrpList_.length > 0) {
		for (String tmp : GrpList_) {
		    if (tmp != null && !tmp.equals("")) {
			builder_dst.addGrpList(tmp);
		    }
		}
	    }
	    builder_dst.setLocalInfo((com.proto.uuos_sdk_pb.UserLocal) LocalInfo.dataChangeCommonToProBufData());

	    for (SSInfoType sSInfoType : SSInfoTypelist) {
		builder_dst.addSSInfoTypelist((com.proto.uuos_sdk_pb.SSInfoType) sSInfoType.dataChangeCommonToProBufData());
	    }

	    Message pbMessage = builder_dst.build();
	    return pbMessage;
	} catch (Exception e) {
	    // TODO: handle exception
	}

	return null;
    }

    /**
     * 从probuf对象获取当前对象
     * 
     * @param builder_src
     * @return
     */
    public void dataChangeProBufDataToCommon(Message builder_src) {
	try {
	    com.proto.uuos_sdk_pb.UserInfo userInfo = (com.proto.uuos_sdk_pb.UserInfo) builder_src;

	    UserTelno = userInfo.getUserTelno();
	    UserName = userInfo.getUserName();
	    password = userInfo.getPassword();
	    UserType = userInfo.getUserType();
	    Priority = userInfo.getPriority();
	    UserStatus = userInfo.getUserStatus();
	    PttPriority = userInfo.getPttPriority();
	    GroupPriority = userInfo.getGroupPriority();
	    Workplace = userInfo.getWorkplace();
	    Address = userInfo.getAddress();
	    Contact = userInfo.getContact();
	    Desc = userInfo.getDesc();
	    addtime = userInfo.getAddtime();
	    Odb = userInfo.getOdb();
	    AuthNodeIDList = userInfo.getAuthNodeIDList();
	    longitude = userInfo.getLongitude();
	    latitude = userInfo.getLatitude();
	    zoom = userInfo.getZoom();
	    UserIconName = userInfo.getUserIconName();
	    UserShowType = userInfo.getUserShowType();
	    UserMediaType = userInfo.getUserMediaType();
	    UserMediaID = userInfo.getUserMediaID();
	    utRegIp = userInfo.getUtRegIp();
	    keep2 = userInfo.getKeep2();
	    keep3 = userInfo.getKeep3();
	    keep4 = userInfo.getKeep4();

	    //
	    StringBuilder builder = new StringBuilder();
	    for (int i = 0; i < userInfo.getGrpListCount(); i++) {
		builder.append(userInfo.getGrpList(i));
		if (i < (userInfo.getGrpListCount() - 1)) {
		    builder.append("#");
		}
	    }

	    GrpList = builder.toString();

	    LocalInfo = new com.springcloud.sc.ucpv5.client.commondata.data.UserLocal();
	    LocalInfo.dataChangeProBufDataToCommon(userInfo.getLocalInfo());

	    SSInfoTypelist = new com.springcloud.sc.ucpv5.client.commondata.data.SSInfoType[userInfo.getSSInfoTypelistCount()];
	    for (int i = 0; i < userInfo.getSSInfoTypelistCount(); i++) {
		SSInfoTypelist[i] = new com.springcloud.sc.ucpv5.client.commondata.data.SSInfoType();
		SSInfoTypelist[i].dataChangeProBufDataToCommon(userInfo.getSSInfoTypelist(i));
	    }
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }
}
